912D - Fishes - CodeForces Solution


data structures graphs greedy probabilities shortest paths *2100

Please click on ads to support us..

Python Code:

import queue
q = queue.PriorityQueue()
(n, m, r, k) = map(int, input().split())
a = min(r, n - r + 1)
b = min(r, m - r + 1)
u = n - 2 * a + 2
v = m - 2 * b + 2
for i in range(1, a + 1):
	q.put((-b * i, i))
t = 0
while k:
	(s, i) = q.get()
	q.put((s + i, i))
	d = min((u if i == a else 2) * (v if s == -b * i else 2), k)
	t -= s * d
	k -= d
print(t / (n - r + 1) / (m - r + 1))


Comments

Submit
0 Comments
More Questions

703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It
1335B - Construct the String